// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@CHART}}-chart/\{{spinalCase ctrl.codeName}}-chart-model.ts.hbs生成
{{#* inline 'initCategorCodeList' codeItems}}
  {{#each codeItems as |codeItem|}}
  {{#codeItem}}
      {
        text: '{{text}}',
        codeName: '{{codeName}}',
        userParams: {{#if codeItem.userParams}}{{json codeItem.userParams}}{{else}}{}{{/if}},
        {{#if codeItem.psCodeItems}}
        codeItems: [
          {{> initCategorCodeList codeItems=codeItem.psCodeItems}}
        ],
        {{/if}}
      }{{#unless @last}},{{/unless}}
  {{/codeItem}}
  {{/each}}
{{/inline}}

{{#* inline 'initSeries' serieses}}
[
{{#each serieses as | series |}}
    {
        name: '{{lowerCase series.name}}',
        caption: '{{lowerCase series.caption}}',
        capPSLanguageRes: '{{series.capPSLanguageRes.lanResTag}}',
        // 分类属性
        catalogField: '{{lowerCase series.catalogField}}',
        // 值属性
        valueField: '{{lowerCase series.valueField}}',
        // 序列索引
        seriesIndex: {{#if series.index}}series.index{{else}}0{{/if}},
        {{#if series.catalogPSCodeList}}
        // 分类代码表
        categorCodeList: {
            type: '{{series.catalogPSCodeList.codeListType}}',
            tag: '{{series.catalogPSCodeList.codeName}}',
            emptytext: '{{series.catalogPSCodeList.emptyText}}',
            codeItems: [ 
              {{> initCategorCodeList codeItems=series.catalogPSCodeList.psCodeItems}}
            ],            
        },
        {{/if}}
        {{#if series.seriesPSCodeList}}
        // 序列代码表
        seriesCodeList: {
            type: '{{series.seriesPSCodeList.codeListType}}',
            tag: '{{series.seriesPSCodeList.codeName}}',
            emptytext: '{{series.seriesPSCodeList.emptyText}}',
        },
        {{/if}}
        // 序列名称属性                  
        seriesField: '{{lowerCase series.seriesField}}',
        // 序列标识属性
        idField: '{{lowerCase series.idField}}',
        // ECharts类型
        eChartsType: '{{series.eChartsType}}',
        // 序列图形类型
        seriesType: '{{series.seriesType}}',
        // 结果集行列模式
        seriesLayoutBy: '{{series.seriesLayoutBy}}',  
        // 基础配置Json内容
        baseOptionJOString: '{{series.baseOptionJOString}}',  
        // 图表数据集对象id
        chartDataSetId: '{{series.psChartDataSet.id}}',  
        // 扩展值4属性
        extValue4Field: '{{series.extValue4Field}}',
        // 图表序列编码
        chartSeriesEncode : {{#if series.psChartSeriesEncode}}{
          getX: ['{{series.psChartSeriesEncode.x}}'],
          getY: ['{{series.psChartSeriesEncode.y}}'],
          category:'{{series.psChartSeriesEncode.category}}',
          value:'{{series.psChartSeriesEncode.value}}',
          xAxisIndex:'{{series.psChartSeriesEncode.psChartXAxis.id}}',
          yAxisIndex:'{{series.psChartSeriesEncode.psChartYAxis.id}}',
        }{{else}}null{{/if}},
        // 用户自定义参数
        {{#if series.userParams}}
        userParams: {
          {{#each series.userParams}}
          '{{@key}}': {{this}}{{#unless @last}},{{/unless}}
          {{/each}}
        }
        {{else}}
        userParams: {}
        {{/if}}
    }{{#unless @last}},{{/unless}} 
    
{{/each}}
]
{{/inline}}

{{#* inline 'initDataSets' dataSets}}
[
{{#each dataSets as | dataSet |}}
    {
        id: '{{dataSet.id}}',
        fields: [
          {{#each dataSet.psChartDataSetFields as | field |}}
            {
              name: '{{field.name}}',
              // 分组模式
              groupMode: '{{field.groupMode}}',
              // 分组属性
              groupField: '{{field.groupField}}',
              codelist: {{#if field.psCodeList}}{
                codeName : '{{field.psCodeList.codeName}}',
                codeListTag : '{{field.psCodeList.codeListTag}}',
              } 
              {{else}}null{{/if}}, 
            },
          {{/each}}           
        ]
    }{{#unless @last}},{{/unless}} 
{{/each}}
]
{{/inline}}

{{#* inline 'initChartXAxises' chartXAxises}}
[
{{#each chartXAxises as | xAxis |}}
    {
        position: '{{xAxis.position}}',
        eChartsType: '{{xAxis.eChartsType}}',
        caption: '{{xAxis.caption}}',
        capPSLanguageRes: '{{xAxis.capPSLanguageRes.lanResTag}}',        
        dataShowMode: {{xAxis.dataShowMode}},
        minValue: '{{xAxis.minValue}}',
        maxValue: '{{xAxis.maxValue}}',
        userParams: {{#if series.userParams}}{{json series.userParams}}{{else}}{}{{/if}},           
    }{{#unless @last}},{{/unless}} 
{{/each}}
]
{{/inline}}

{{#* inline 'initChartGrids' chartGirds}}
[
{{#each chartGirds as | grid |}}
    {
        // 基础配置Json内容
        baseOptionJOString: '{{grid.baseOptionJOString}}', 
    }{{#unless @last}},{{/unless}} 
{{/each}}
]
{{/inline}}

import { IChartModel } from '@/core';
function getModel(): IChartModel {
    return {
        cssName: "{{#if ctrl.psSysCss}}{{ctrl.psSysCss.cssName}}{{/if}}",             
        caption: '{{ctrl.caption}}',
        controlType: '{{ctrl.controlType}}',
        codeName: '{{ctrl.codeName}}',
        entityCodeName: '{{ctrl.psAppDataEntity.codeName}}',
        name: '{{ctrl.name}}',
        noSort: '{{ctrl.noSort}}',
        sortDir: '{{ctrl.minorSortDir}}',
        limit: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}1000{{/if}},      
        paging: {
            defaultPageSize: {{#if ctrl.pagingSize}}{{ctrl.pagingSize}}{{else}}20{{/if}},
        },
        // 排序属性
        sortField: '{{#if ctrl.minorSortPSAppDEField}}{{lowerCase ctrl.minorSortPSAppDEField.codeName}}{{/if}}',
        // 序列集合
        serieses: {{#if ctrl.psDEChartSerieses}}getChartSeries(){{else}}[]{{/if}},
        // 数据集
        dataSets: {{#if ctrl.psChartDataSets}}getChartDataSets(){{else}}[]{{/if}},
        // 用户自定义参数
        userParams: {{#if ctrl.userParams}}{{json ctrl.userParams}}{{else}}{}{{/if}},
        // xAxis集合
        chartXAxises: {{#if ctrl.psChartXAxises}}getChartXAxises(){{else}}[]{{/if}},
        // yAxis集合
        chartYAxises: {{#if ctrl.psChartYAxises}}getChartYAxises(){{else}}[]{{/if}},
        // 直角坐标表格集合
        chartGrids: {{#if ctrl.psChartGrids}}getChartGrids(){{else}}[]{{/if}},
        // 实体图表标题对象
        chartTitle: {{#if ctrl.psDEChartTitle}}{
          showTitle: {{ctrl.psDEChartTitle.showTitle}},
          title: '{{ctrl.psDEChartTitle.title}}',
          titlePSLanguageRes:'{{ctrl.psDEChartTitle.titlePSLanguageRes.lanResTag}}',        
          subTitle: '{{ctrl.psDEChartTitle.subTitle}}',
          subTitlePSLanguageRes: '{{ctrl.psDEChartTitle.subTitlePSLanguageRes.lanResTag}}',
          titlePos: '{{ctrl.psDEChartTitle.titlePos}}',
        }{{else}}null{{/if}},
        // 实体图表图例对象
        chartLegend: {{#if ctrl.psDEChartLegend}}{
          showLegend: {{ctrl.psDEChartLegend.showLegend}},
          legendPos: '{{ctrl.psDEChartLegend.legendPos}}',
        }{{else}}null{{/if}},        
    }
}

function getChartSeries() {
    return {{> initSeries serieses=ctrl.psDEChartSerieses}}
}

function getChartDataSets() {
    return {{> initDataSets dataSets=ctrl.psChartDataSets}}
}

function getChartXAxises() {
    return {{> initChartXAxises chartXAxises=ctrl.psChartXAxises}}
}

function getChartYAxises() {
    return {{> initChartXAxises chartXAxises=ctrl.psChartYAxises}}
}

function getChartGrids() {
    return {{> initChartGrids chartGrids=ctrl.psChartGrids}}
}

export const model = getModel()